<template>
  <div class="category-container">
    <div class="header">
      <van-search
        v-model="value"
        shape="round"
        background="#fff"
        placeholder="搜索商品"
      />
    </div>
    <div class="main">
      <div class="sider-bar">
        <van-sidebar v-model="activeKey">
          <van-sidebar-item
            :title="item.name"
            v-for="(item, index) in SiderBarNav"
            :key="item.id"
            @click="tolist(item.id, index)"
            :class="{ active: index == idx }"
          />
        </van-sidebar>
      </div>
      <div class="main-right">
        <div class="banner">
          <img :src="listdata.banner_url" />
        </div>
        <div class="category-list">
          <h2>{{ listdata.name }}分类</h2>
          <ul class="list">   
            <li
              v-for="item in listdata.subList"
              :key="item.idx"
              @click="todetail(item)"
            >
              <img :src="item.wap_banner_url" alt="" />
              <p>{{ item.name }}</p>
            </li>
            <li></li>
            <li></li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { indexaction, currentaction } from "@/api/Category";
export default {
  data() {
    return {
      value: "",
      activeKey: "",
      SiderBarNav: [],
      listdata: {},
      idx: "0",
    };
  },
  methods: {
    async getdataSiderBarNav() {
      let res1 = await indexaction();
      this.SiderBarNav = res1.categoryList;
      let res2 = await currentaction({ id: this.SiderBarNav[this.idx].id });
      this.listdata = res2.data.currentOne;
    },
    async tolist(id, index) {
      this.idx = index;
      let res2 = await currentaction({ id });
      this.listdata = res2.data.currentOne;
    },
    todetail(item) {
      this.$router.push({ path: "/categoryDetail", query: { id:item.id,name:item.name } });
    },
  },
  created() {
    this.getdataSiderBarNav();
  },
};
</script>

<style scoped lang='scss'>
.category-container {
  padding-bottom: 100px;
  .header {
    padding: 0 20px 41px 20px;
    border-bottom: 1px solid rgba(232, 232, 232, 1);
  }
  .main {
    background-color: #f8f8f8;
    display: flex;
    .sider-bar {
      width: 164px;
      height: 100%;
      .active {
        color: #cea62a;
      }
    }
    .main-right {
      height: 237.8px;
      padding: 20px 20px 0 20px;
      flex: 1;
      .banner {
        height: 100%;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .category-list {
        padding-top: 73.15px;
        h2 {
          font-size: 30px;
          color: #333333;
          letter-spacing: 0;
          font-weight: 500;
          text-align: center;
          margin-bottom: 28.5px;
        }
        .list {
          display: flex;
          justify-content: space-between;
          flex-wrap: wrap;
          li {
            width: 140px;
            height: 170px;
            text-align: center;
            font-size: 24px;
            color: #333333;
            letter-spacing: 0;
            font-weight: 500;
            margin-bottom: 38.5px;
            img {
              height: 137px;
            }
            &:nth-last-child(1) {
              width: 0;
              height: 0;
              overflow: hidden;
            }
            &:nth-last-child(2) {
              width: 0;
              height: 0;
              overflow: hidden;
            }
          }
        }
      }
    }
  }
}
</style>

<style lang="scss">
.category-container {
  .van-search {
    height: 70px;
    padding: 0;
  }
  .van-sidebar-item--select::before {
    width: 0;
    height: 0;
    background-color: transparent;
  }
  .van-sidebar-item {
    height: 134px;
    background-color: #fff;
    font-size: 30px;
    color: #333333;
    letter-spacing: 0;
    font-weight: 400;
    padding: 60px 47px 32px 53px;
  }
}
</style>